import 'dart:convert';

class Auth {
  int? id;
  String? username;
  String? accessToken;
  String? refreshToken;

  Auth({this.id, this.username, this.accessToken, this.refreshToken});

  @override
  String toString() {
    return 'Auth(id: $id, username: $username, accessToken: $accessToken, refreshToken: $refreshToken)';
  }

  factory Auth.fromMap(Map<String, dynamic> data) => Auth(
        id: data['id'] as int?,
        username: data['username'] as String?,
        accessToken: data['accessToken'] as String?,
        refreshToken: data['refreshToken'] as String?,
      );

  Map<String, dynamic> toMap() => {
        'id': id,
        'username': username,
        'accessToken': accessToken,
        'refreshToken': refreshToken,
      };

  /// `dart:convert`
  ///
  /// Parses the string and returns the resulting Json object as [Auth].
  factory Auth.fromJson(String data) {
    return Auth.fromMap(json.decode(data) as Map<String, dynamic>);
  }

  /// `dart:convert`
  ///
  /// Converts [Auth] to a JSON string.
  String toJson() => json.encode(toMap());

  Auth copyWith({
    int? id,
    String? username,
    String? accessToken,
    String? refreshToken,
  }) {
    return Auth(
      id: id ?? this.id,
      username: username ?? this.username,
      accessToken: accessToken ?? this.accessToken,
      refreshToken: refreshToken ?? this.refreshToken,
    );
  }
}
